<?php 
class Admin_LoginController extends Zend_Controller_Action
{
	public function indexAction()
	{
		$loginForm = new Application_Form_Login();
		//$loginForm->setAction($this->view->url(array('module'=>'admin', 'controller'=>'login','action'=>'index'), 'default'));
    
		$request = $this->getRequest();
		echo Zend_Auth::getInstance()->getIdentity();
		if ($request->isPost())
		{
			// Validate form
			if ($loginForm->isValid($request->getPost()))
			{
				$values = $loginForm->getValues();

				// Attempt login
				$dbAdapter = Zend_Db_Table::getDefaultAdapter();
	
				$login = new Application_Model_Login($dbAdapter);
	 
				if ($login->login($values['login'], $values['passwd']))
				{
					$this->_redirect('admin');
				}
				else
				{
					$loginForm->populate($values);
					$this->view->errorMessage = 'Nom d\'utilisateur ou mot de passe incorrect';
				}
			}
			else
			{
				$loginForm->populate($loginForm->getValues());
			}
		}
		$this->view->loginForm = $loginForm;
		$this->_helper->layout->disableLayout();
	}
 
	public function logoutAction()
	{
		$login = new Application_Model_Login();
		$login->logout();
		$this->_redirect('admin');
	}
}